<?php
$isReloadable = false;
$isPopUp = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.tabDati.php');

$aExp = array();
$aExp['head']['data_ora'] = time();
$aExp['head']['server'] = $_SERVER['HTTP_HOST'];
$aExp['head']['data_base'] = RGL_DB_NAME.'@'.RGL_DB_HOST;
$aExp['head']['tipo'] = 'setDati';

$sql_sel = "SELECT *" .
		" FROM rgl_set_dati " .
		" WHERE id_set_dati = ".reqVarInt('sd').
		" ORDER BY cod_set_dati ";
$objDB->query($sql_sel,'selRecX');
if(!$acX = $objDB->fetch('selRecX')) { 
	die('id errato '.reqVar('sd'));
}
$codSetDati = $acX['cod_set_dati'];
$aExp['body']['rec'] = $acX;
$aExp['body']['dati'] = array();
$sql_sel = "SELECT *" 
		." FROM rgl_def_dato "
		." WHERE id_set_dati = ".reqVar('sd')
		." ORDER BY cod_dato ";
$objDB->query($sql_sel,'selRecZ');		
while($acZ = $objDB->fetch('selRecZ')) { 
	$aExp['body']['dati'][] = $acZ;
}

$sExpC = gzcompress(serialize($aExp));

headerDownLoad(strlen($sExpC),"setDati_".$codSetDati."_".date('ymdHis').".ser");
echo $sExpC;
exit();
